<template>
	<!-- 重点人员添加页面 -->
	<view class="building-add">
		<view class="add-content">
			<view class="add-item">
				<view class="item-left">重点人员类型<text>*</text></view>
				<view class="item-right" @click="typeShow=true">{{ type }}</view>
			</view>
			<navigator class="add-item" url="../../Public/import" hover-class="none">
				<view class="item-left">问题青少年<text>*</text></view>
				<view class="item-right">{{ userId_text }}</view>
			</navigator>
			<view class="add-item">
				<view class="item-left">描述</view>
				<view class="item-right"><textarea v-model="conncet" placeholder-style="color:#999;font-size:26rpx" placeholder="请输入描述"></textarea></view>
			</view>
		</view>
		<view class="btn">
			<view class="btn-1" @click="handleSubmit">保存</view>
		</view>
		
		<u-toast ref="uToast" />
		<!-- 类型 -->
		<u-select v-model="typeShow" :list="dictList" @confirm="confirm"></u-select>
	</view>
</template>

<script>
	export default{
		data() {
			return{
				typeShow: false,
				dictList:[],
				campusPersonType:'',// 类型数字
				type:'请选择',// 类型汉字
				userId:'',
				userId_text:'请选择',
				conncet:'',
				ampusKeypersonnelId:''
			}
		},
		onShow() {
			let importPer = uni.getStorageSync('importPer')
			this.userId_text = importPer.name
			this.userId = importPer.id
		},
		onLoad(options) {
			this.ampusKeypersonnelId = options.id
		},
		mounted() {
			this.getDictionaries()
			this.getCampusKeypersonnelById()
		},
		methods:{
			getCampusKeypersonnelById() {
				let params = {
					ampusKeypersonnelId:this.ampusKeypersonnelId
				}
				this.$u.api.getCampusKeypersonnelById(params)
					.then(res => {
						console.log(res)
						if(res.code == 200) {
							this.userId = res.result.userId
							this.userId_text = res.result.name
							this.conncet = res.result.conncet
							this.campusPersonType = res.result.campusPersonType
							this.dictList.forEach(item => {
								if(item.value == res.result.campusPersonType) {
									this.type = item.label
								}
							})
						}
					})
					.catch(err => {
						console.log(err)
					})
			},
			// 字典
			getDictionaries() {
				let params = {
					dictCode:'import_type_dict'
				}
				this.$u.api.dictionaries(params)
					.then(res => {
						// console.log(res)
						if(res.code == 200) {
							res.result.forEach(item => {
								this.dictList.push({
									value:item.value,
									label:item.text
								})
							})
						}
					})
					.catch(err => {
						console.log(err)
					})
			},
			confirm(e) {
				console.log(e)
				this.type = e[0].label
				this.campusPersonType = e[0].value
			},
			// 提交
			handleSubmit() {
				if(this.campusPersonType == '') {
					return this.$refs.uToast.show({
						title: '请选择重点人员类型'
					})
				}
				if(this.userId == '') {
					return this.$refs.uToast.show({
						title: '请选择重点人员'
					})
				}
				let params = {
					conncet:this.conncet,
					userId:this.userId,
					campusPersonType:this.campusPersonType,
					id:this.ampusKeypersonnelId
				}
				uni.removeStorageSync('importPer')
					this.$u.api.editCampusKeypersonnel(params)
						.then(res => {
							console.log(res)
							if(res.code == 200) {
								uni.showToast({
									title:'修改成功',
									icon:'success'
								})
							}
						})
						.catch(err => {
							console.log(err)
							uni.showToast({
								title:'修改失败',
								icon:'none'
							})
						})
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	.building-add{
		background-color: #f5f6f7;
		min-height: 100vh;
		.add-head{
			display: flex;
			justify-content: space-between;
			align-items: center;
			background-color: #fff;
			height: 180rpx;
			padding: 20rpx;
			.head-left{
				.head-left-1{
					color: #000;
					font-size: 28rpx;
					font-weight: 600;
				}
				.head-left-2{
					color: #999;
					font-size: 24rpx;
					margin-top: 20rpx;
				}
			}
			.head-right{
				background-color: #cecece;
				display: flex;
				justify-content: center;
				align-items: center;
				border-radius: 10rpx;
				width: 150rpx;
				height: 150rpx;
				.img{
					width: 50%;
					height: 50%;
				}
				.img2{
					width: 100%;
					height: 100%;
				}
			}
		}
		.add-content{
			margin-top: 20rpx;
			padding-bottom: 110rpx;
			.add-item{
				display: flex;
				justify-content: space-between;
				align-items: flex-start;
				padding: 20rpx;
				background-color: #fff;
				border-bottom: 1px solid #f4f1f1;
				.item-left{
					color: #333;
					font-size: 28rpx;
					min-width: 100rpx;
					text{
						color: #DD524D;
					}
				}
				.item-right{
					font-size: 27rpx;
					color: #999;
					input{
						text-align: right;
					}
					input::placeholder{
					    font-size: 26rpx;
					    color: #999;
					}
					textarea{
						
					}
				}
			}
		}
		.btn{
			width: 100%;
			height: 110rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			color: #fff;
			font-size: 30rpx;
			background-color: #f4f1f1;
			position: fixed;
			bottom: 0;
			left: 0;
			border-top: 1px solid #CCE6FF;
			.btn-1{
				background-color: #007AFF;
				display: flex;
				justify-content: center;
				align-items: center;
				width: 600rpx;
				height: 80rpx;
				border-radius: 40rpx;
			}
		}
	}
</style>
